{% extends 'backstage/teacher/base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}

{% block title %}Task{% endblock %}

{% block setting_content %}
    <div class="card w-100">
        <h4 class="card-header">
            {{ _('Tasks') }}
            {% if is_start() %}
                <small class="text-muted">
                    {{ pagination.total|default(0) }}
                </small>
            {% endif %}
        </h4>
        {% if is_start() %}
            <div class="card-body">
                {% if pagination.items %}
                    <div class="table-responsive">
                        <table class="table table-striped table-hover table-sm">
                            <thead>
                            <tr class="text-center">
                                <th>#</th>
                                <th>{{ _('Problem') }}</th>
                                <th>{{ _('UUID') }}</th>
                                <th style="width:10%">{{ _('Score') }}</th>
                                <th class="col">{{ _('Remark') }}</th>
                                <th>{{ _('Actions') }}</th>
                            </tr>
                            </thead>
                            {% for task in pagination.items %}
                                <tr class="text-center">
                                    <td scope="row">{{ config['SOLUTION_PER_PAGE']*(page-1) + loop.index }}</td>
                                    <td>
                                        <span class="badge badge-pill badge-primary">
                                            {{ task.problem }}
                                        </span>
                                    </td>
                                    <td>
                                        <a href="{{ url_for('backstage.get_solution', filename=task.solution_uuid) }}"
                                           target="_blank">
                                            {{ task.solution_uuid }}
                                        </a>
                                    </td>
                                    <form action="{{ url_for('teacher.change', task_id=task.id) }}" method="post"
                                          role="form">
                                        {{ form.csrf_token() }}
                                        <td>
                                            {% if task.score is not none %}
                                                {{ form.score(class="form-control form-control-sm text-center", value=task.score) }}
                                            {% else %}
                                                {{ form.score(class="form-control form-control-sm text-center") }}
                                            {% endif %}
                                        </td>
                                        <td>
                                            {% if task.remark %}
                                                {{ form.remark(class="form-control form-control-sm text-center", value=task.remark) }}
                                            {% else %}
                                                {{ form.remark(class="form-control form-control-sm text-center") }}
                                            {% endif %}
                                        </td>
                                        <td>
                                            <button class="btn btn-info btn-sm" type="submit">
                                                <span class="oi oi-circle-check"></span> {{ _("Update") }}
                                            </button>
                                        </td>
                                    </form>
                                </tr>
                            {% endfor %}
                        </table>
                    </div>
                    <div class="page-footer">
                        {{ render_pagination(pagination) }}
                    </div>
                {% else %}
                    {% include "backstage/tips/no_solution.html" %}
                {% endif %}
            </div>
        {% else %}
            {% include "backstage/tips/no_start.html" %}
        {% endif %}
    </div>
{% endblock %}
